<template>
  <Dialog :title="dialogTitle" v-model="dialogVisible">
    <el-form
      ref="formRef"
      :model="formData"
      :rules="formRules"
      label-width="100px"
      v-loading="formLoading"
    >
      <el-form-item label="编号" prop="number">
        <el-input v-model="formData.number" placeholder="请输入编号" />
      </el-form-item>
      <el-form-item label="500万游戏编号" prop="matchId">
        <el-input v-model="formData.matchId" placeholder="请输入500万游戏编号" />
      </el-form-item>
      <el-form-item label="赛事" prop="match">
        <el-input v-model="formData.match" placeholder="请输入赛事" />
      </el-form-item>
      <el-form-item label="赛事500万url" prop="matchUrl">
        <el-input v-model="formData.matchUrl" placeholder="请输入赛事500万url" />
      </el-form-item>
      <el-form-item label="分析" prop="analysis">
        <el-input v-model="formData.analysis" placeholder="请输入分析" />
      </el-form-item>
      <el-form-item label="颜色" prop="color">
        <el-input v-model="formData.color" placeholder="请输入颜色" />
      </el-form-item>
      <el-form-item label="开赛时间" prop="openTime">
        <el-date-picker
          v-model="formData.openTime"
          type="date"
          value-format="x"
          placeholder="选择开赛时间"
        />
      </el-form-item>
      <el-form-item label="总进球赔率" prop="goalOdds">
        <el-input v-model="formData.goalOdds" placeholder="请输入总进球赔率" />
      </el-form-item>
      <el-form-item label="让球赔率" prop="letOdds">
        <el-input v-model="formData.letOdds" placeholder="请输入让球赔率" />
      </el-form-item>
      <el-form-item label="半全场赔率" prop="halfWholeOdds">
        <el-input v-model="formData.halfWholeOdds" placeholder="请输入半全场赔率" />
      </el-form-item>
      <el-form-item label="不让球赔率" prop="notLetOdds">
        <el-input v-model="formData.notLetOdds" placeholder="请输入不让球赔率" />
      </el-form-item>
      <el-form-item label="比分赔率" prop="scoreOdds">
        <el-input v-model="formData.scoreOdds" placeholder="请输入比分赔率" />
      </el-form-item>
      <el-form-item label="让球" prop="letBall">
        <el-input v-model="formData.letBall" placeholder="请输入让球" />
      </el-form-item>
      <el-form-item label="主队" prop="homeTeam">
        <el-input v-model="formData.homeTeam" placeholder="请输入主队" />
      </el-form-item>
      <el-form-item label="下注状态 0 不可下注 1 可下注 2 已取消" prop="state">
        <el-input v-model="formData.state" placeholder="请输入下注状态 0 不可下注 1 可下注 2 已取消" />
      </el-form-item>
      <el-form-item label="客队" prop="visitingTeam">
        <el-input v-model="formData.visitingTeam" placeholder="请输入客队" />
      </el-form-item>
      <el-form-item label="是否单关 0 否 1 是" prop="isSingle">
        <el-input v-model="formData.isSingle" placeholder="请输入是否单关 0 否 1 是" />
      </el-form-item>
      <el-form-item label="比赛下注截止时间" prop="deadline">
        <el-date-picker
          v-model="formData.deadline"
          type="date"
          value-format="x"
          placeholder="选择比赛下注截止时间"
        />
      </el-form-item>
      <el-form-item label="半全场结果" prop="halfFullCourt">
        <el-input v-model="formData.halfFullCourt" placeholder="请输入半全场结果" />
      </el-form-item>
      <el-form-item label="开奖结果" prop="award">
        <el-input v-model="formData.award" placeholder="请输入开奖结果" />
      </el-form-item>
      <el-form-item label="属于哪天的比赛时间" prop="startTime">
        <el-date-picker
          v-model="formData.startTime"
          type="date"
          value-format="x"
          placeholder="选择属于哪天的比赛时间"
        />
      </el-form-item>
      <el-form-item label="比分" prop="score">
        <el-input v-model="formData.score" placeholder="请输入比分" />
      </el-form-item>
      <el-form-item label="主队链接" prop="homeTeamUrl">
        <el-input v-model="formData.homeTeamUrl" placeholder="请输入主队链接" />
      </el-form-item>
      <el-form-item label="客队链接" prop="visitTeamUrl">
        <el-input v-model="formData.visitTeamUrl" placeholder="请输入客队链接" />
      </el-form-item>
      <el-form-item label="胜赔" prop="winPay">
        <el-input v-model="formData.winPay" placeholder="请输入胜赔" />
      </el-form-item>
      <el-form-item label="平赔" prop="drawPay">
        <el-input v-model="formData.drawPay" placeholder="请输入平赔" />
      </el-form-item>
      <el-form-item label="客赔" prop="visitPay">
        <el-input v-model="formData.visitPay" placeholder="请输入客赔" />
      </el-form-item>
      <el-form-item label="让球胜赔" prop="letWinPay">
        <el-input v-model="formData.letWinPay" placeholder="请输入让球胜赔" />
      </el-form-item>
      <el-form-item label="让球平赔" prop="letDrawPay">
        <el-input v-model="formData.letDrawPay" placeholder="请输入让球平赔" />
      </el-form-item>
      <el-form-item label="让球客赔" prop="letVisitPay">
        <el-input v-model="formData.letVisitPay" placeholder="请输入让球客赔" />
      </el-form-item>
      <el-form-item label="胜赔概率" prop="winRate">
        <el-input v-model="formData.winRate" placeholder="请输入胜赔概率" />
      </el-form-item>
      <el-form-item label="平赔概率" prop="drawWinRate">
        <el-input v-model="formData.drawWinRate" placeholder="请输入平赔概率" />
      </el-form-item>
      <el-form-item label="客赔概率" prop="visitWinRate">
        <el-input v-model="formData.visitWinRate" placeholder="请输入客赔概率" />
      </el-form-item>
      <el-form-item label="让球胜赔概率" prop="letWinRate">
        <el-input v-model="formData.letWinRate" placeholder="请输入让球胜赔概率" />
      </el-form-item>
      <el-form-item label="让球平赔概率" prop="letDrawWinRate">
        <el-input v-model="formData.letDrawWinRate" placeholder="请输入让球平赔概率" />
      </el-form-item>
      <el-form-item label="让球客赔概率" prop="letVisitWinRate">
        <el-input v-model="formData.letVisitWinRate" placeholder="请输入让球客赔概率" />
      </el-form-item>
      <el-form-item label="胜赔" prop="winFlag">
        <el-input v-model="formData.winFlag" placeholder="请输入胜赔" />
      </el-form-item>
      <el-form-item label="平赔" prop="drawWinFlag">
        <el-input v-model="formData.drawWinFlag" placeholder="请输入平赔" />
      </el-form-item>
      <el-form-item label="客赔" prop="visitWinFlag">
        <el-input v-model="formData.visitWinFlag" placeholder="请输入客赔" />
      </el-form-item>
      <el-form-item label="让球胜赔" prop="letWinFlag">
        <el-input v-model="formData.letWinFlag" placeholder="请输入让球胜赔" />
      </el-form-item>
      <el-form-item label="让球平赔" prop="letDrawWinFlag">
        <el-input v-model="formData.letDrawWinFlag" placeholder="请输入让球平赔" />
      </el-form-item>
      <el-form-item label="让球客赔" prop="letVisitWinFlag">
        <el-input v-model="formData.letVisitWinFlag" placeholder="请输入让球客赔" />
      </el-form-item>
      <el-form-item label="胜赔" prop="winSelect">
        <el-input v-model="formData.winSelect" placeholder="请输入胜赔" />
      </el-form-item>
      <el-form-item label="平赔" prop="drawWinSelect">
        <el-input v-model="formData.drawWinSelect" placeholder="请输入平赔" />
      </el-form-item>
      <el-form-item label="客赔" prop="visitWinSelect">
        <el-input v-model="formData.visitWinSelect" placeholder="请输入客赔" />
      </el-form-item>
      <el-form-item label="让球胜赔" prop="letWinSelect">
        <el-input v-model="formData.letWinSelect" placeholder="请输入让球胜赔" />
      </el-form-item>
      <el-form-item label="让球平赔" prop="letDrawWinSelect">
        <el-input v-model="formData.letDrawWinSelect" placeholder="请输入让球平赔" />
      </el-form-item>
      <el-form-item label="让球客赔" prop="letVisitWinSelect">
        <el-input v-model="formData.letVisitWinSelect" placeholder="请输入让球客赔" />
      </el-form-item>
      <el-form-item label="投注倾向" prop="trendWin">
        <el-input v-model="formData.trendWin" placeholder="请输入投注倾向" />
      </el-form-item>
      <el-form-item label="欧赔对比" prop="ouDiff">
        <el-input v-model="formData.ouDiff" placeholder="请输入欧赔对比" />
      </el-form-item>
      <el-form-item label="热队" prop="hotTeam">
        <el-input v-model="formData.hotTeam" placeholder="请输入热队" />
      </el-form-item>
      <el-form-item label="500-投注分析" prop="zw">
        <el-input v-model="formData.zw" placeholder="请输入500-投注分析" />
      </el-form-item>
      <el-form-item label="500-投注量大小描述" prop="mountDesc">
        <el-input v-model="formData.mountDesc" placeholder="请输入500-投注量大小描述" />
      </el-form-item>
      <el-form-item label="500-投注量规模" prop="mount">
        <el-input v-model="formData.mount" placeholder="请输入500-投注量规模" />
      </el-form-item>
      <el-form-item label="筛选排序" prop="selectSort">
        <el-input v-model="formData.selectSort" placeholder="请输入筛选排序" />
      </el-form-item>
      <el-form-item label="比分预测" prop="scoreSelect">
        <el-input v-model="formData.scoreSelect" placeholder="请输入比分预测" />
      </el-form-item>
      <el-form-item label="能力值对比" prop="teamScore">
        <el-input v-model="formData.teamScore" placeholder="请输入能力值对比" />
      </el-form-item>
      <el-form-item label="是否显示" prop="isView">
        <el-input v-model="formData.isView" placeholder="请输入是否显示" />
      </el-form-item>
      <el-form-item label="进球数指数" prop="ballNumPredict">
        <el-input v-model="formData.ballNumPredict" placeholder="请输入进球数指数" />
      </el-form-item>
      <el-form-item label="进球数" prop="ballNum">
        <el-input v-model="formData.ballNum" placeholder="请输入进球数" />
      </el-form-item>
      <el-form-item label="欧赔主胜概率" prop="ouHomeRate">
        <el-input v-model="formData.ouHomeRate" placeholder="请输入欧赔主胜概率" />
      </el-form-item>
      <el-form-item label="欧赔平赔概率" prop="ouDrawRate">
        <el-input v-model="formData.ouDrawRate" placeholder="请输入欧赔平赔概率" />
      </el-form-item>
      <el-form-item label="欧赔主负概率" prop="ouVisitRate">
        <el-input v-model="formData.ouVisitRate" placeholder="请输入欧赔主负概率" />
      </el-form-item>
      <el-form-item label="欧赔差异" prop="ouResult">
        <el-input v-model="formData.ouResult" placeholder="请输入欧赔差异" />
      </el-form-item>
      <el-form-item label="主队半场进球数-算法值" prop="homeAlgScoreBan">
        <el-input v-model="formData.homeAlgScoreBan" placeholder="请输入主队半场进球数-算法值" />
      </el-form-item>
      <el-form-item label="客队半场进球数-算法值" prop="awayAlgScoreBan">
        <el-input v-model="formData.awayAlgScoreBan" placeholder="请输入客队半场进球数-算法值" />
      </el-form-item>
      <el-form-item label="主队全场进球数-算法值" prop="homeAlgScoreQuan">
        <el-input v-model="formData.homeAlgScoreQuan" placeholder="请输入主队全场进球数-算法值" />
      </el-form-item>
      <el-form-item label="客队全场进球数-算法值" prop="awayAlgScoreQuan">
        <el-input v-model="formData.awayAlgScoreQuan" placeholder="请输入客队全场进球数-算法值" />
      </el-form-item>
      <el-form-item label="主队半场进球数-推荐值" prop="homePreScoreBan">
        <el-input v-model="formData.homePreScoreBan" placeholder="请输入主队半场进球数-推荐值" />
      </el-form-item>
      <el-form-item label="客队半场进球数-推荐值" prop="awayPreScoreBan">
        <el-input v-model="formData.awayPreScoreBan" placeholder="请输入客队半场进球数-推荐值" />
      </el-form-item>
      <el-form-item label="主队全场进球数-推荐值" prop="homePreScoreQuan">
        <el-input v-model="formData.homePreScoreQuan" placeholder="请输入主队全场进球数-推荐值" />
      </el-form-item>
      <el-form-item label="客队全场进球数-推荐值" prop="awayPreScoreQuan">
        <el-input v-model="formData.awayPreScoreQuan" placeholder="请输入客队全场进球数-推荐值" />
      </el-form-item>
      <el-form-item label="推荐理由" prop="remark">
        <el-input v-model="formData.remark" placeholder="请输入推荐理由" />
      </el-form-item>
    </el-form>
    <template #footer>
      <el-button @click="submitForm" type="primary" :disabled="formLoading">确 定</el-button>
      <el-button @click="dialogVisible = false">取 消</el-button>
    </template>
  </Dialog>
</template>
<script setup lang="ts">
import { FootballMatchApi, FootballMatchVO } from '@/api/lottery/sporttery/footballmatch'

/** 竞猜足彩比赛 表单 */
defineOptions({ name: 'FootballMatchForm' })

const { t } = useI18n() // 国际化
const message = useMessage() // 消息弹窗

const dialogVisible = ref(false) // 弹窗的是否展示
const dialogTitle = ref('') // 弹窗的标题
const formLoading = ref(false) // 表单的加载中：1）修改时的数据加载；2）提交的按钮禁用
const formType = ref('') // 表单的类型：create - 新增；update - 修改
const formData = ref({
  id: undefined,
  number: undefined,
  matchId: undefined,
  match: undefined,
  matchUrl: undefined,
  analysis: undefined,
  color: undefined,
  openTime: undefined,
  goalOdds: undefined,
  letOdds: undefined,
  halfWholeOdds: undefined,
  notLetOdds: undefined,
  scoreOdds: undefined,
  letBall: undefined,
  homeTeam: undefined,
  state: undefined,
  visitingTeam: undefined,
  isSingle: undefined,
  deadline: undefined,
  halfFullCourt: undefined,
  award: undefined,
  startTime: undefined,
  score: undefined,
  homeTeamUrl: undefined,
  visitTeamUrl: undefined,
  winPay: undefined,
  drawPay: undefined,
  visitPay: undefined,
  letWinPay: undefined,
  letDrawPay: undefined,
  letVisitPay: undefined,
  winRate: undefined,
  drawWinRate: undefined,
  visitWinRate: undefined,
  letWinRate: undefined,
  letDrawWinRate: undefined,
  letVisitWinRate: undefined,
  winFlag: undefined,
  drawWinFlag: undefined,
  visitWinFlag: undefined,
  letWinFlag: undefined,
  letDrawWinFlag: undefined,
  letVisitWinFlag: undefined,
  winSelect: undefined,
  drawWinSelect: undefined,
  visitWinSelect: undefined,
  letWinSelect: undefined,
  letDrawWinSelect: undefined,
  letVisitWinSelect: undefined,
  trendWin: undefined,
  ouDiff: undefined,
  hotTeam: undefined,
  zw: undefined,
  mountDesc: undefined,
  mount: undefined,
  selectSort: undefined,
  scoreSelect: undefined,
  teamScore: undefined,
  isView: undefined,
  ballNumPredict: undefined,
  ballNum: undefined,
  ouHomeRate: undefined,
  ouDrawRate: undefined,
  ouVisitRate: undefined,
  ouResult: undefined,
  homeAlgScoreBan: undefined,
  awayAlgScoreBan: undefined,
  homeAlgScoreQuan: undefined,
  awayAlgScoreQuan: undefined,
  homePreScoreBan: undefined,
  awayPreScoreBan: undefined,
  homePreScoreQuan: undefined,
  awayPreScoreQuan: undefined,
  remark: undefined
})
const formRules = reactive({
  number: [{ required: true, message: '编号不能为空', trigger: 'blur' }],
  match: [{ required: true, message: '赛事不能为空', trigger: 'blur' }],
  color: [{ required: true, message: '颜色不能为空', trigger: 'blur' }],
  openTime: [{ required: true, message: '开赛时间不能为空', trigger: 'blur' }],
  goalOdds: [{ required: true, message: '总进球赔率不能为空', trigger: 'blur' }],
  letOdds: [{ required: true, message: '让球赔率不能为空', trigger: 'blur' }],
  halfWholeOdds: [{ required: true, message: '半全场赔率不能为空', trigger: 'blur' }],
  notLetOdds: [{ required: true, message: '不让球赔率不能为空', trigger: 'blur' }],
  scoreOdds: [{ required: true, message: '比分赔率不能为空', trigger: 'blur' }],
  letBall: [{ required: true, message: '让球不能为空', trigger: 'blur' }],
  homeTeam: [{ required: true, message: '主队不能为空', trigger: 'blur' }],
  state: [{ required: true, message: '下注状态 0 不可下注 1 可下注 2 已取消不能为空', trigger: 'blur' }],
  visitingTeam: [{ required: true, message: '客队不能为空', trigger: 'blur' }],
  isSingle: [{ required: true, message: '是否单关 0 否 1 是不能为空', trigger: 'blur' }],
  deadline: [{ required: true, message: '比赛下注截止时间不能为空', trigger: 'blur' }],
  startTime: [{ required: true, message: '属于哪天的比赛时间不能为空', trigger: 'blur' }]
})
const formRef = ref() // 表单 Ref

/** 打开弹窗 */
const open = async (type: string, id?: number) => {
  dialogVisible.value = true
  dialogTitle.value = t('action.' + type)
  formType.value = type
  resetForm()
  // 修改时，设置数据
  if (id) {
    formLoading.value = true
    try {
      formData.value = await FootballMatchApi.getFootballMatch(id)
    } finally {
      formLoading.value = false
    }
  }
}
defineExpose({ open }) // 提供 open 方法，用于打开弹窗

/** 提交表单 */
const emit = defineEmits(['success']) // 定义 success 事件，用于操作成功后的回调
const submitForm = async () => {
  // 校验表单
  await formRef.value.validate()
  // 提交请求
  formLoading.value = true
  try {
    const data = formData.value as unknown as FootballMatchVO
    if (formType.value === 'create') {
      await FootballMatchApi.createFootballMatch(data)
      message.success(t('common.createSuccess'))
    } else {
      await FootballMatchApi.updateFootballMatch(data)
      message.success(t('common.updateSuccess'))
    }
    dialogVisible.value = false
    // 发送操作成功的事件
    emit('success')
  } finally {
    formLoading.value = false
  }
}

/** 重置表单 */
const resetForm = () => {
  formData.value = {
    id: undefined,
    number: undefined,
    matchId: undefined,
    match: undefined,
    matchUrl: undefined,
    analysis: undefined,
    color: undefined,
    openTime: undefined,
    goalOdds: undefined,
    letOdds: undefined,
    halfWholeOdds: undefined,
    notLetOdds: undefined,
    scoreOdds: undefined,
    letBall: undefined,
    homeTeam: undefined,
    state: undefined,
    visitingTeam: undefined,
    isSingle: undefined,
    deadline: undefined,
    halfFullCourt: undefined,
    award: undefined,
    startTime: undefined,
    score: undefined,
    homeTeamUrl: undefined,
    visitTeamUrl: undefined,
    winPay: undefined,
    drawPay: undefined,
    visitPay: undefined,
    letWinPay: undefined,
    letDrawPay: undefined,
    letVisitPay: undefined,
    winRate: undefined,
    drawWinRate: undefined,
    visitWinRate: undefined,
    letWinRate: undefined,
    letDrawWinRate: undefined,
    letVisitWinRate: undefined,
    winFlag: undefined,
    drawWinFlag: undefined,
    visitWinFlag: undefined,
    letWinFlag: undefined,
    letDrawWinFlag: undefined,
    letVisitWinFlag: undefined,
    winSelect: undefined,
    drawWinSelect: undefined,
    visitWinSelect: undefined,
    letWinSelect: undefined,
    letDrawWinSelect: undefined,
    letVisitWinSelect: undefined,
    trendWin: undefined,
    ouDiff: undefined,
    hotTeam: undefined,
    zw: undefined,
    mountDesc: undefined,
    mount: undefined,
    selectSort: undefined,
    scoreSelect: undefined,
    teamScore: undefined,
    isView: undefined,
    ballNumPredict: undefined,
    ballNum: undefined,
    ouHomeRate: undefined,
    ouDrawRate: undefined,
    ouVisitRate: undefined,
    ouResult: undefined,
    homeAlgScoreBan: undefined,
    awayAlgScoreBan: undefined,
    homeAlgScoreQuan: undefined,
    awayAlgScoreQuan: undefined,
    homePreScoreBan: undefined,
    awayPreScoreBan: undefined,
    homePreScoreQuan: undefined,
    awayPreScoreQuan: undefined,
    remark: undefined
  }
  formRef.value?.resetFields()
}
</script>
